package com.ruoyi.security.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.security.domain.AfDeviceCamera;
import com.ruoyi.security.service.IAfDeviceCameraService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 摄像头Controller
 *
 * @author cjie
 * @date 2022-07-13
 */
@Api(tags = " 摄像头")
@RestController
@RequestMapping("/afDeviceCamera")
public class AfDeviceCameraController extends BaseController {
    @Autowired
    private IAfDeviceCameraService afDeviceCameraService;

    /**
     * 查询摄像头列表
     */
    @ApiOperation(value="查询摄像头列表", notes="查询摄像头列表")
    @PreAuthorize(hasPermi = "security:afDeviceCamera:list")
    @GetMapping("/list")
    public TableDataInfo list(AfDeviceCamera afDeviceCamera) {
        startPage();
        List<AfDeviceCamera> list = afDeviceCameraService.selectAfDeviceCameraList(afDeviceCamera);
        return getDataTable(list);
    }

    /**
     * 导出摄像头列表
     */
    @ApiOperation(value="导出摄像头列表", notes="导出摄像头列表")
    @PreAuthorize(hasPermi = "security:afDeviceCamera:export")
    @Log(title = "摄像头", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AfDeviceCamera afDeviceCamera) throws IOException {
        List<AfDeviceCamera> list = afDeviceCameraService.selectAfDeviceCameraList(afDeviceCamera);
        ExcelUtil<AfDeviceCamera> util = new ExcelUtil<AfDeviceCamera>(AfDeviceCamera.class);
        util.exportExcel(response, list, "摄像头数据");
    }
    /**
     * 获取摄像头详细信息
     */
    @ApiOperation(value="获取摄像头详细信息", notes="获取摄像头详细信息")
    @PreAuthorize(hasPermi = "security:afDeviceCamera:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(afDeviceCameraService.selectAfDeviceCameraById(id));
    }

    /**
     * 新增摄像头
     */
    @ApiOperation(value="新增摄像头", notes="新增摄像头")
    @PreAuthorize(hasPermi = "security:afDeviceCamera:add")
    @Log(title = "摄像头", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AfDeviceCamera afDeviceCamera) {
        return toAjax(afDeviceCameraService.insertAfDeviceCamera(afDeviceCamera));
    }

    /**
     * 修改摄像头
     */
    @ApiOperation(value="修改摄像头", notes="修改摄像头")
    @PreAuthorize(hasPermi = "security:afDeviceCamera:edit")
    @Log(title = "摄像头", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AfDeviceCamera afDeviceCamera) {
        return toAjax(afDeviceCameraService.updateAfDeviceCamera(afDeviceCamera));
    }

    /**
     * 删除摄像头
     */
    @ApiOperation(value="删除摄像头", notes="删除摄像头")
    @ApiImplicitParam(name = "ids", value = "摄像头ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "security:afDeviceCamera:remove")
    @Log(title = "摄像头", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(afDeviceCameraService.deleteAfDeviceCameraByIds(ids));
    }

    /**
     * 删除摄像头
     */
    @ApiOperation(value="同步云上摄像头", notes="同步云上摄像头")
    @PreAuthorize(hasPermi = "security:afDeviceCamera:add")
    @Log(title = "同步摄像头", businessType = BusinessType.INSERT)
    @GetMapping("/getList")
    public AjaxResult getOnlineList() {
        return toAjax(afDeviceCameraService.getOnlineList());
    }

    @ApiOperation(value="获取萤石云token", notes="获取萤石云token")
    @PreAuthorize(hasPermi = "security:afDeviceCamera:add")
    @GetMapping("/ysAccessToken")
    public AjaxResult getYSAccessToken() {
        return AjaxResult.success(afDeviceCameraService.getAccessToken());
    }
}
